(function() {
	//用户收藏
	var role = require("./role");
	var BusCon = require("../../core/bus/_con");
	var UserCon = require("../../core/user/_con");
	var GoodsCon = require("../../core/goods/_con");
	var AchCon = require("../../core/ach/_con");
	var db = require("../../core/db/index");
	var config = require("../../core/_include/config");
	var ResponObj = require("../_include/responObj");

	module.exports = {
		prefix: "/user/collect",
		get: {
			//获取已经登陆的用户的收藏商品的ID数组
			//.params.num 返回的最大数量||5
			"/": function() {
				var user = role.getUser(this);
				var query = this.request.query;
				var collectGoods = user.getCollect(query.num, query.page);
				this.body = ResponObj("json", collectGoods);
			},
			"/detail": function() {
				var user = role.getUser(this);
				var query = this.request.query;
				var collectGoods = user.getCollectDetail(query.num, query.page)
				this.body = ResponObj("json", collectGoods);
			},
			"/by_bus_id/:bus_id": function() {
				var user = role.getUser(this);
				var query = this.request.query;
				var bus_id = this.params.bus_id;
				var collectGoods = user.getCollectDetail_byBusId(bus_id, query.num, query.page)
				this.body = ResponObj("json", collectGoods);
			}
		},
		post: {
			//添加商品编号到购物车
			"/add_goods": function() {
				var user = role.getUser(this);
				var goods_id = this.request.body.goods_id;
				if (!goods_id) {
					throwCusError("参数错误")
				}
				var collect = user.addGoodsToCollect(goods_id)
				this.body = ResponObj("json", collect)
			},
		},
		"delete": {
			"/remove_goods": function() {
				var user = role.getUser(this);
				var goods_id = this.request.body.goods_id;
				if (!goods_id) {
					throwCusError("参数错误")
				}
				var collect = user.removeGoodsFromCollect(goods_id)
				this.body = ResponObj("json", collect);
			}
		}
	}
}());